package com.pinusmusic.service.impl;

import com.pinusmusic.dao.AdminDao;
import com.pinusmusic.dao.impl.AdminDaoImpl;
import com.pinusmusic.domain.Favorite;
import com.pinusmusic.domain.PageBean;
import com.pinusmusic.domain.User;
import com.pinusmusic.service.AdminService;

import java.util.List;

public class AdminServiceImpl implements AdminService {
    private AdminDao ad = new AdminDaoImpl();
    @Override
    public boolean findAdminByNameAndPassword(String adminname, String adminpassword) {
        return ad.findAdminByNameAndPassword(adminname,adminpassword);
    }

    @Override
    public List<User> findAllUser() {
        return ad.findAllUser();
    }

    @Override
    public void deleteUserByUid(int uid) {
        ad.deleteUserByUid(uid);
    }

    @Override
    public void updateComment(int uid) {
        ad.updateComment(uid);
    }

    @Override
    public int findCount() {
        return ad.findCount();
    }

    @Override
    public PageBean<User> findUserByPage(int pageSize, int currentPage) {
        //封装PageBean
        PageBean<User> pageBean = new PageBean<>();
        //设置当前页面
        pageBean.setCurrentPage(currentPage);
        //设置每页显示的记录数
        pageBean.setPageSize(pageSize);
        //设置每页的数据 - dao查
        int start = (currentPage - 1) * pageSize;
        List<User> list = ad.findByPage(start,pageSize);
        pageBean.setList(list);
        // 总记录数
        int count = ad.findCount();
        pageBean.setTotalCount(count);
        // 总页码
        int totalPage = count % pageSize == 0 ? (count/pageSize):(count/pageSize + 1);
        pageBean.setTotalPage(totalPage);
        return pageBean;
    }

    @Override
    public void deleteFavByUid(int uid) {
        ad.deleteFavByUid(uid);
    }

    @Override
    public void deleteComByUid(int uid) {
        ad.deleteComByUid(uid);
    }

    @Override
    public void open(int parseInt) {
        ad.open(parseInt);
    }

    @Override
    public List<Favorite> findFavByUid(int uid) {
        return ad.findFavByUid(uid);
    }

}
